package com.btpj.blog_server.service;

import com.btpj.blog_server.entity.Category;
import com.btpj.blog_server.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CategoryService {

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    CategoryMapper categoryMapper;

    public List<Category> getAllCategories() {
        return categoryMapper.getAllCategories();
    }

    public boolean addCategory(Category category) {
        return categoryMapper.addCategory(category) == 1;
    }

    public Category getCategoryByName(String name) {
        return categoryMapper.getCategoryByName(name);
    }

    public boolean deleteCategories(String ids) {
        String[] idArr = ids.split(",");
        return categoryMapper.deleteCategories(idArr) == idArr.length;
    }

    public boolean updateCategory(Category category) {
        return categoryMapper.updateCategory(category) == 1;
    }
}
